package com.taotao.portal.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.taotao.portal.pojo.CartItem;
import com.taotao.portal.service.CartService;

@Controller
public class CartController {
	@Autowired
	private CartService cartService;
	
	@RequestMapping("/cart/add/{itemId}")
	public String addCartItem(@PathVariable long itemId,@RequestParam(defaultValue="1") Integer num,
			HttpServletRequest request,HttpServletResponse response){
		cartService.addCartItem(itemId, num, request, response);
		return "cartSuccess";
	}
	
	@RequestMapping("/cart/cart")
	public String getCartItem(HttpServletRequest request,HttpServletResponse response,
			Map<String,Object> map){
		List<CartItem> list=cartService.getCartItemList(request, response);
		map.put("cartList", list);
		return "cart";
	}
	
	@RequestMapping("/cart/delete/{itemId}")
	public String deleteCartItem(@PathVariable long itemId,HttpServletRequest request,HttpServletResponse response){
		cartService.deleteCartItem(itemId, request, response);
		return "cart";
	}
}
